export const schema = {
    type: "page",
    title: "团队列表",
    toolbar: {
        visibleOn: 'acl.can("team:create")',
        type: "button",
        actionType: "link",
        icon: "fa fa-plus pull-left",
        level: "success",
        label: "新建团队",
        link: "/team/create"
    },
    body: {
        type: "crud",
        api: "/api/team",
        columnsTogglable: false,
        filter: {
            title: "",
            submitText: "",
            panelClassName: 'm-b-none bg-gd no-border',
            bodyClassName: 'wrapper-sm',
            controls: [
                {
                    type: "text",
                    name: "keywords",
                    label: "团队查询",
                    placeholder: "团队名称/联系人/法人"
                },

                {
                    type: "select",
                    name: "type",
                    label: "团队类型",
                    source: "/api/setting/team_type",
                    clearable: true
                },

                {
                    type: "select",
                    name: "service_target",
                    label: "服务对象",
                    source: "/api/setting/service_target",
                    clearable: true
                },

                {
                    type: 'button-toolbar',
                    buttons: [
                        {
                            type: "button",
                            label: "导出",
                            level: "info",
                            actionType: "url",
                            url: "/api/team?asExcel=1&keywords=${keywords}&type=${type}&service_target=${service_target}&parent_id=${parent_id}"
                        },

                        {
                            type: "submit",
                            label: "搜索",
                            primary: true
                        }
                    ]
                }

            ]
        },
        showFooter: false,
        toolbarInline: true,
        toolbar: {
            type: "button",
            label: "全部通知",
            level: "info",
            size: 'sm',
            actionType: "dialog",
            dialog: {
                title: "发送站内信",
                body: {
                    type: "form",
                    api: 'post:/api/team/notify?parent_id=${query.parent_id}',
                    controls: [
                        {
                            type: "textarea",
                            name: "content",
                            label: false
                        }
                    ]
                }
            }
        },
        bulkActions: [
            {
                type: "button",
                label: "通知",
                actionType: "dialog",
                level: "info",
                dialog: {
                    title: "发送站内信",
                    body: {
                        type: "form",
                        api: 'post:/api/team/notify/${ids}',
                        controls: [
                            {
                                type: "textarea",
                                name: "content",
                                label: false
                            }
                        ]
                    }
                }
            }
        ],
        columns: [
            {
                name: "id",
                label: "团队ID",
                width: 50
            },
            {
                name: "name",
                label: "团队名称",
                type: "tpl",
                tpl: "<a data-link='/team/view/${id}'>${name}</a>"
            },
            {
                name: "org_id",
                label: "所属机构",
                type: "tpl",
                tpl: `<% if (data.acl.can("org:view")) { %>
                    <a data-link='/org/view/<%= data.org.id %>'><%= data.org.name %></a>
                    <% } else { %>
                        <span><%= data.org.name %></span>
                        <% } %>`
            },
            {
                label: "联系人",
                name: "contact_name"
            },
            {
                name: "parent_id",
                label: "上级团队",
                type: "tpl",
                tpl: `
                <% if (data.parent_team) { %><a data-link='/team/view/<%= data.parent_id %>'><%= data.parent_team.name %></a><% } else { %><span class='text-muted'>-</span><% } %>
                <% if (data.parent_team && data.query.parent_id) { %><a class='btn btn-primary m-l-xs btn-xs' data-link='/team/list?org_id=<%= data.query.org_id %>&parent_id=<%= data.parent_team.parent_id %>'>上级列表</a><% } %>
                `
            },
            {
                name: "sub_team_count",
                label: "下级团队数",
                type: "tpl",
                tpl:
                "<a data-link='/team/list?parent_id=${id}&org_id=${query.org_id}'>${sub_team_count}</a>"
            },
            {
                label: "项目数",
                name: "project_count",
                // sortable: true,
                type: "tpl",
                tpl: "<a data-link='/project/list?team_id=${id}'>${project_count}</a>"
            },
            {
                label: "志愿者人数",
                name: "team_size",
                sortable: true,
                type: 'tpl',
                tpl: "<a data-link='/volunteer?team_id=${id}'>${team_size}</a>"
            },


            {
                name: "reward_time",
                sortable: true,
                label: "志愿时长"
            },

            {
                label: "操作",
                type: "operation",
                width: 180,
                visibleOn: "acl.can('team:create')",
                buttons: [
                    {
                        type: "button",
                        size: "xs",
                        level: "info",
                        label: "编辑",
                        actionType: "link",
                        link: "/team/edit/${id}"
                    },

                    {
                        type: "button",
                        size: "xs",
                        level: "primary",
                        label: "权限管理",
                        actionType: "link",
                        link: "/team/acl/${id}"
                    },

                    {
                        visibleOn: "!data.blacked",
                        type: "button",
                        size: "xs",
                        label: "加入黑名单",
                        level: "danger",
                        confirmText: "确定要加入黑名单？",
                        actionType: "dialog",
                        dialog: {
                            title: "请输入拉黑原因",
                            body: {
                                type: "form",
                                api: "/api/team/black/$id",
                                controls: [
                                    {
                                        label: false,
                                        type: "text",
                                        name: "reason"
                                    }
                                ]
                            }
                        }
                    },

                    {
                        visibleOn: "data.blacked",
                        type: "button",
                        size: "xs",
                        label: "不拉黑",
                        level: "success",
                        confirmText: "确定要不拉黑？",
                        actionType: "ajax",
                        api: "/api/team/unblack/$id"
                    },

                    // {
                    //     type: "button",
                    //     size: "xs",
                    //     label: "删除",
                    //     level: "danger",
                    //     confirmText: "确定要删除？",
                    //     actionType: "ajax",
                    //     api: "delete:/api/team/$id"
                    // }
                ]
            }
        ]
    }
};
